package com.study.sp3;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;
import lombok.experimental.Accessors;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author zhuzi
 * 2024/4/26 15:58
 */
public class Demo {
    @Test
    public void test() {

        Stu stu = new Stu();
        String jsonString1 = JSON.toJSONString(stu);
        System.out.println(jsonString1);

        String jsonString = JSONObject.toJSONString(stu, SerializerFeature.WriteDateUseDateFormat);
        System.out.println(jsonString);

    }

    @Data
    @Accessors(chain = true)
    public static class Stu {
        //@JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private Date date = new Date();
        private LocalDate ld = LocalDate.now();
        //@JSONField(format = "yyyy-MM-dd HH:mm:ss")
        private LocalDateTime time = LocalDateTime.now();
    }

}
